package com.liy.teaching.core.service;


import com.liy.teaching.core.entity.UserEntity;
import com.liy.teaching.core.entity.UserGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    // 模拟数据库
    private static Map<String, UserDetails> userDao = new HashMap();

    static {

        // 权限集合
        ArrayList<UserGrantedAuthority> list = new ArrayList<>();

        list.add(new UserGrantedAuthority("sys.user.delete"));
        list.add(new UserGrantedAuthority("sys.user.add"));
        list.add(new UserGrantedAuthority("sys.user.update"));
        list.add(new UserGrantedAuthority("sys.user.query"));
        list.add(new UserGrantedAuthority("sys.user.query"));
        list.add(new UserGrantedAuthority("ROLE_admin"));

        userDao.put("user1001", new UserEntity("user1001", "user1001",list));
    }


    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return userDao.get(username);
    }
}
